"use strict";

var Chat = {};

Chat.socket = null;

Chat.connect = (function(host) {
    if ('WebSocket' in window) {
        Chat.socket = new WebSocket(host);
    } else if ('MozWebSocket' in window) {
        Chat.socket = new MozWebSocket(host);
    } else {
        Console.log('此浏览器不支持消息发布');
        return;
    }

    Chat.socket.onopen = function () {
        
    };

    Chat.socket.onclose = function () {
       
    };

    Chat.socket.onmessage = function (message) {
        Console.log(message.data);
    };
});

Chat.initialize = function() {
    if (window.location.protocol == 'http:') {
        Chat.connect('ws://' + window.location.host + '/palace/websocket/chat');
    } else {
        Chat.connect('wss://' + window.location.host + '/palace/websocket/chat');
    }
};


var Console = {};

Console.log = (function(message) {
    $.messager.show({
		title:'系统消息',
		msg:message,
		showType:'show'
	});
});

Chat.initialize();